// Town script for town 33: first power source

begintownscript;

variables;

int choice,x,i,j,tick1,tick2,tick3;

body;

beginstate INIT_STATE;

	if (get_flag(32,1) == 1) {
			if (get_flag(32,0) == 1) {	
					set_terrain(35,34,388);
					set_terrain(39,30,388);
					set_flag(33,4,0);
					set_flag(33,5,0);
					}
			}

	if (get_flag(33,4) == 1)
			set_terrain(35,34,384);
	
	if (get_flag(33,5) == 1)
			set_terrain(39,30,384);

	if (get_flag(33,0) == 1) {
			set_terrain(31,12,385);
			set_terrain(31,15,385);
			set_terrain(34,12,385);
			set_terrain(37,12,385);
			set_terrain(38,6,388);
			set_terrain(41,4,388);
			set_terrain(34,8,388);
			set_terrain(30,8,388);
			set_terrain(27,8,388);
			set_terrain(24,8,388);
			set_terrain(21,8,388);
			set_terrain(18,8,388);
			set_terrain(15,8,388);
			set_terrain(23,12,388);
			set_terrain(26,15,388);
			set_terrain(29,23,388);
			set_terrain(24,25,388);
			set_terrain(21,25,388);
			set_terrain(20,25,388);
			set_terrain(19,25,388);
			set_terrain(28,25,388);
			set_terrain(39,28,388);
			}

break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;

	if (get_flag(33,1) == 1) {
			message_dialog("Last time you were here, you switched the power off. The wizards have turned the power on in your absence","");
			set_flag(33,1,0);
			}

// Thing with the destruction of power source 1

if (get_flag(200,5) == 1) {
		tick1 = get_flag(250,1) * 256 + get_flag(250,6);
		
		if (get_current_tick() == (tick1 + 10)) {
				if (get_flag(33,2) == 1) {
						message_dialog("You waited a while and can now see (and hear and smell) the result of putting the power sources on full mode. The place blows up!","");
						set_flag(33,0,1);
						set_flag(200,5,2);
						
						set_terrain(31,12,385);
						set_terrain(31,15,385);
						set_terrain(34,12,385);
						set_terrain(37,12,385);
						set_terrain(38,6,388);
						set_terrain(41,4,388);
						set_terrain(34,8,388);
						set_terrain(30,8,388);
						set_terrain(27,8,388);
						set_terrain(24,8,388);
						set_terrain(21,8,388);
						set_terrain(18,8,388);
						set_terrain(15,8,388);
						set_terrain(23,12,388);
						set_terrain(26,15,388);
						set_terrain(29,23,388);
						set_terrain(24,25,388);
						set_terrain(21,25,388);
						set_terrain(20,25,388);
						set_terrain(19,25,388);
						set_terrain(28,25,388);
						set_terrain(39,28,388);
						set_terrain(34,20,388);
						set_terrain(34,22,388);
						force_instant_terrain_redraw();				
						}
				}
		}
		
// recharge of control panel town 32

if (get_flag(32,0) == 1) {
	if (get_flag(33,4) == 1) {
			if (get_flag(33,5) == 1) {
					if (get_flag(32,1) == 1) {
							set_flag(32,1,0);
							}
					}
			}
	}

break;

beginstate 10;
	move_to_new_town(32,19,5);
break;

beginstate 11;
if (get_flag(33,0) == 1) {
		message_dialog("As you blew up this place, the control panel also malfunctions. Better go away before the wizards see what you did.","");
		end();
		}

reset_dialog();
add_dialog_str(0,"This control panel has certainly something to do with the power sources all around you. In that case, this is probably the thing you should meddle with.",0);
add_dialog_str(1,"There are three buttons on this panel of which its clear what they do. There's also a small screen on which you can see the current mode. It reads _Half power mode._ Which button would you like to press?",0);
add_dialog_choice(0,"Off/On");
add_dialog_choice(1,"Half power");
add_dialog_choice(2,"Full power");
choice = run_dialog(1);

	if (choice == 1) {
			if (get_flag(33,1) == 0) {
					message_dialog("You switched the power off. This is foolish, and the wizards here can turn everything on again if they must. Maybe you should try something else.","");
					set_flag(33,1,1);
					set_terrain(31,12,388);
					set_terrain(31,15,388);
					set_terrain(34,12,388);
					set_terrain(37,12,388);
					force_instant_terrain_redraw();
					end();
					}
			
			if (get_flag(33,1) == 1) {
					message_dialog("You switched the power on. Of all things, turning the power on is maybe the most foolish thing to do. Helping the enemy is always a bit foolish, actually.","");
					set_flag(33,1,0);
					set_terrain(31,12,384);
					set_terrain(31,15,384);
					set_terrain(34,12,384);
					set_terrain(37,12,384);
					force_instant_terrain_redraw();
					end();
					}
			}
	
	if (choice == 2) {
			if (get_flag(33,1) == 1) {
					message_dialog("The power is off. Maybe you should turn it on first?","");
					end();
					}
				if (get_flag(33,2) == 0) {
						message_dialog("As the power is already on half, pressing this button is quite useless. Maybe you should try something else?","");
						end();
						}
					message_dialog("The power is now on half. This is the normal mode of these power sources. Maybe adding power will help to heat this place up.","");
					set_flag(33,2,0);
					end();
					}
	
	if (choice == 3) {
			if (get_flag(33,1) == 1) {
					message_dialog("The power is off. Maybe you should turn it on first?","");
					end();
					}
				if (get_flag(33,2) == 1) {
						message_dialog("As the power is already on full, pressing this button is quite useless. Maybe you should try something else?","");
						end();
						}
					message_dialog("The power is now on full. You push the power sources to their limits. Maybe, if you wait a while, the place will go up in smoke.","");
					
					tick1 = get_current_tick();
					set_flag(250,1,tick1 / 256);
					set_flag(250,6,tick1 % 256);
					set_flag(33,2,1);
					set_flag(200,5,1);
					end();
					}
break;

beginstate 12;
reset_dialog();
add_dialog_str(0,"Even though the whole place is currently off-line, this control panel still seems to be working. There is one, big, red button. Press it?",0);
add_dialog_choice(0,"Press it");
add_dialog_choice(1,"Leave it");
choice = run_dialog(1);

	if (choice == 1) {
			if (get_flag(33,3) == 0) {
					message_dialog("You press the button and wait. You hear the lasers in the room in front of you humming slightly, with growing intensity.","Through a loudspeaker you only discovered now, you hear the following: _Please pull levers to recharge button power sources._ This thing is to reactivate the control panel in the small room that got you here!");
					set_flag(33,3,1);
					end();
					}
				message_dialog("You press the button and wait. The panel cools off. You turned it off.","");
				set_flag(33,3,0);
				end();
				}
break;

beginstate 13;
if (get_flag(33,6) == 1)
		end();
	message_dialog("You thought people only worked here, but now you see that's not the only thing that happens here. The workers also seem to live here. You can hear soft voices of people talking to one another.","Something that interests you more, is the smell of food. How strange. You wonder how they get food down here.");
	set_flag(33,6,1);
break;

beginstate 14;
if (get_flag(33,7) == 1)
		end();
	message_dialog("This is the kitchen. Now you can see how the workers get their food. There's a hole in the ceiling, through which food falls down now and then.","");
	set_flag(33,7,1);
break;